https://leetcode.cn/problems/path-with-maximum-gold/
class Solution {
public:
    int ret,m,n;
    int dx[4]={0,0,1,-1};
    int dy[4]={1,-1,0,0};
    bool check[16][16];

    void dfs(vector<vector<int>>& grid,int row,int col,int path)
    {
        ret=ret>path?ret:path;

        for(int i=0;i<4;i++)
        {
            int x=row+dx[i],y=col+dy[i];
            if(x>=0&&x<m &&y>=0&&y<n &&!check[x][y] &&grid[x][y])
            {
                check[x][y]=true;
                dfs(grid,x,y,path+grid[x][y]);
                //回溯
                check[x][y]=false;
            }
        }
    }
    int getMaximumGold(vector<vector<int>>& grid) {
        m=grid.size(),n=grid[0].size();
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(grid[i][j])
                {
                    check[i][j]=true;
                    dfs(grid,i,j,grid[i][j]);
                    check[i][j]=false;
                }
            }
        }
        return ret;
    }
};